package com.manage.infoboard.contorll;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.manage.infoboard.service.IInfoboardService;
import com.manage.infoboard.vo.Infoboard;
import com.ym.monitor.MethodTimeActive;

@Controller
@RequestMapping("/infoboard")
public class InfoboardController {

	@Autowired
	private IInfoboardService infoboardService;
	
	
	/**TODO 查询历史
	 * @param model
	 * @param time
	 * @return
	 * ModelAndView
	 */
	@RequestMapping("/view_instant_Infoboard")
	public ModelAndView view_instant_infoboard(ModelMap model,Integer sec){
		List<Infoboard> infoboardes = infoboardService.selectInfoboard(sec);
		Integer total = infoboardService.selectInfoboardCount(sec);
		model.put("infoboardes", infoboardes);
		model.put("total", total);
		return new ModelAndView("instant_Infoboard_view");
	}
	
	@RequestMapping("/view_monitor")
	public ModelAndView view_monitor(ModelMap model){
		model.put("monitors", MethodTimeActive.methodTest);
		return new ModelAndView("view_monitor");
	}
	
	/**
	 * @Title: initBinder
	 * @Description: 注册日期处理
	 * @param binder
	 * @throws
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		dateFormat.setLenient(false);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				dateFormat, false));
	}
}
